package com.app.controller.backstage;

import com.app.service.BrowseNumberService;
import com.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class BrowseNumberController {


    @Autowired
    BrowseNumberService browseNumberService;

    /**
     * 新增访问
     */
    @GetMapping("/addBrowse")
    @ResponseBody
    public Result<Object> addBrowse(HttpServletRequest request, Integer type) {
        String token = request.getHeader("token");
        if (type != null && type != 0) {
            int code = browseNumberService.addBrowse(token, type);
            if (code == 200) {
                return Result.success("新增访问成功");
            } else {
                return Result.error(code, "操作失败");
            }
        }
        int code = browseNumberService.addBrowse(token);
        if (code == 200) {
            return Result.success("新增访问成功");
        } else {
            return Result.error(code, "操作失败");
        }
    }


}
